package com.td.spring.beans;

/**
 * bean的内容及元数据,包装bean的实体
 * @author td
 * @date 2018/6/4
 */
public class BeanDefinition {

    private Object bean;

    private Class  beanClass;

    private String beanClassname;

    private PropertyValues propertyValues;

    public BeanDefinition() {
    }

    public Object getBean() {
        return bean;
    }

    public void setBean(Object bean) {
        this.bean = bean;
    }

    public Class getBeanClass() {
        return beanClass;
    }

    public void setBeanClass(Class beanClass) {
        this.beanClass = beanClass;
    }

    public String getBeanClassname() {

        return beanClassname;
    }

    public void setBeanClassname(String beanClassname) {
        this.beanClassname = beanClassname;
        try {
            this.beanClass = Class.forName(beanClassname);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    private void checkReadyToAddProperty() {
        synchronized (this) {
            if (this.propertyValues == null) {
                this.propertyValues = new PropertyValues();
            }
        }
    }

    public PropertyValues getPropertyValues() {
        checkReadyToAddProperty();
        return propertyValues;
    }

    public void setPropertyValues(PropertyValues propertyValues) {
        checkReadyToAddProperty();
        this.propertyValues = propertyValues;
    }
}
